<!DOCTYPE html>


<html lang="zh-Hans">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
     40+岁大龄码农的自我修养
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">
  
<link rel="stylesheet" href="/css/custom.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

<link rel="alternate" href="/atom.xml" title="40+岁大龄码农的自我修养" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      



<!-- Subtitle -->

<div id="main">
  <section class="outer">
  
  
  <article class="articles">
    
    
    
    
    <article
  id="post-tieba-louzhonglou"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/19/tieba-louzhonglou/"
    >python爬取贴吧楼中楼</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/19/tieba-louzhonglou/" class="article-date">
  <time datetime="2015-09-19T12:21:06.000Z" itemprop="datePublished">2015-09-19</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>贴吧把每个帖子每页的楼主楼回复都放到一个json数据里面.<br>首先是找出这个json连接,<br>用charles抓包发现<br><img src="https://ww2.sinaimg.cn/large/7293e3b7jw1ew81ayffluj20tx09940u.jpg"><br>链接是这个样子的,</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http:&#x2F;&#x2F;tieba.baidu.com&#x2F;p&#x2F;totalComment?t&#x3D;1442661243&amp;tid&#x3D;3924896002&amp;fid&#x3D;1627732&amp;pn&#x3D;1&amp;see_lz&#x3D;0</span><br></pre></td></tr></table></figure>
<p>分析后发现,t = 1442661243这个数字是时间,可以用python得time.time()函数得到, tid=3924896002是帖子的数字没啥好说的,<br>fid=1627732是论坛id我想应该是每个贴吧的数字id,比如dota2贴吧是:1627732.</p>
<p>用bs4分析每个帖子的数据,拼凑出这个链接来就ok.</p>
<p>这是代码,不过不完美.还需要用re把表情 语音什么的过滤掉.根据每个回帖的id遍历字典找到相应的楼中楼回复.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">#!&#x2F;usr&#x2F;bin&#x2F;env python</span><br><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"></span><br><span class="line">import requests</span><br><span class="line">from bs4 import BeautifulSoup</span><br><span class="line">import json</span><br><span class="line">import time</span><br><span class="line"></span><br><span class="line">url &#x3D; &#39;http:&#x2F;&#x2F;tieba.baidu.com&#x2F;p&#x2F;4044110950&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">req &#x3D; requests.get(url)</span><br><span class="line">soup &#x3D; BeautifulSoup(req.text, &quot;html.parser&quot;)</span><br><span class="line">forum_ids &#x3D; soup.find(&#39;div&#39;, class_&#x3D;&#39;p_postlist&#39;).find(&#39;div&#39;, class_&#x3D;&#39;l_post l_post_bright j_l_post clearfix  &#39;).get(&#39;data-field&#39;)</span><br><span class="line">forum_id &#x3D; json.loads(forum_ids)[&#39;content&#39;][&#39;forum_id&#39;]</span><br><span class="line">localTime &#x3D; int(time.time())</span><br><span class="line">commentURL &#x3D; &#39;http:&#x2F;&#x2F;tieba.baidu.com&#x2F;p&#x2F;totalComment?t&#x3D;&#39; + str(localTime) + &#39;&amp;tid&#x3D;&#39; + str(url.split(&#39;&#x2F;&#39;)[-1]) + &#39;&amp;fid&#x3D;&#39;+str(forum_id)+&#39;&amp;pn&#x3D;1&amp;see_lz&#x3D;0&#39;</span><br><span class="line"></span><br><span class="line">print commentURL</span><br><span class="line">commentreq &#x3D; requests.get(commentURL)</span><br><span class="line"></span><br><span class="line">for k, v in commentreq.json()[&#39;data&#39;][&#39;comment_list&#39;].items():</span><br><span class="line">    for j in v[&#39;comment_info&#39;]:</span><br><span class="line">        print j[&#39;username&#39;].encode(&#39;utf-8&#39;),</span><br><span class="line">        print j[&#39;content&#39;].encode(&#39;utf-8&#39;)</span><br><span class="line">    print</span><br><span class="line">    print</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-mac10-10-install-mysql"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/18/mac10-10-install-mysql/"
    >MAC10.10 下安装mySQL方法和设置</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/18/mac10-10-install-mysql/" class="article-date">
  <time datetime="2015-09-18T11:12:20.000Z" itemprop="datePublished">2015-09-18</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>mac10.10下可以用brew安装mySQL,</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install mysql</span><br></pre></td></tr></table></figure>
<p>安装完成后, 正常可以用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql.server start</span><br></pre></td></tr></table></figure>
<p>启动mysql.</p>
<p>但是我这次安装后提示,</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql.server start</span><br><span class="line">zsh: command not found: mysql.server</span><br></pre></td></tr></table></figure>
<p>往前翻brew安装记录找到这个</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">The &#96;brew link&#96; step did not complete successfully</span><br><span class="line">The formula built, but is not symlinked into &#x2F;usr&#x2F;local</span><br><span class="line">Could not symlink share&#x2F;man&#x2F;man8&#x2F;mysqld.8</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;share&#x2F;man&#x2F;man8 is not writable.</span><br><span class="line"></span><br><span class="line">You can try again using:</span><br><span class="line">  brew link mysql</span><br></pre></td></tr></table></figure>

<p>然后根据’Could not symlink share/man/man8/mysqld.8<br>/usr/local/share/man/man8 is not writable.’搜到网上高手的解决办法,<a target="_blank" rel="noopener" href="http://apple.stackexchange.com/questions/192227/make-files-in-usr-local-writable-for-homebrew">高手</a><br>就是运行一个命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chown -R &#96;whoami&#96; &#x2F;usr&#x2F;local</span><br></pre></td></tr></table></figure>

<p>再启动mysql服务器就行了.<br>进入mysql的命令是:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -uroot -p</span><br></pre></td></tr></table></figure>
<p>初始登陆没有密码,直接按回车.<br>如果需要设置密码可以用以下命令.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;usr&#x2F;local&#x2F;bin&#x2F;mysqladmin -u root password &#39;root&#39;</span><br></pre></td></tr></table></figure>
<p>分号里面root就是密码,可以根据需要改成自己的.</p>
<p>在mysql里面,如果输入错误命令后,再输入其他命令也无效了,输入”\c”后就可以重新返回命令行了.</p>
<p>还有就是windows下mysql安装完成后,需要设置环境变量后才能使用mysql命令.</p>
<p>在python中操作MySQL数据库,需要安装一个叫MySQL db的第三方库才行.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo pip install MySQL-python</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MySQL/" rel="tag">MySQL</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-webstorm-jQuery"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/15/webstorm-jQuery/"
    >WebStorm安装jQuery自动提示和补全的方法</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/15/webstorm-jQuery/" class="article-date">
  <time datetime="2015-09-15T12:25:28.000Z" itemprop="datePublished">2015-09-15</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>webstorm这款IDE默认是不提示和补全jQuery语法的, 需要手动安装一下.</p>
<ul>
<li><p>打开webstorm的设置,找到Languages &amp; Framewords – JavaScript – Libaraies,<br><img src="https://ww4.sinaimg.cn/large/7293e3b7jw1ew3eumvo76j20sx0erdhq.jpg"></p>
</li>
<li><p>点击Add选项, Name:里输入随便一个名字,比如jQuery, Frameswork type选择jQuery, 下面第一个加号选择从jQuery官网上下载来的压缩版文件,第二个加号输入 HTTP://api.jQuery.com<br><img src="https://ww4.sinaimg.cn/large/7293e3b7jw1ew3f05hvwdj20d30mqdgi.jpg"></p>
</li>
</ul>
<p>最后点击ok就可以了.</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%BD%AF%E4%BB%B6/" rel="tag">软件</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-empty-trash"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/09/empty-trash/"
    >MAC快速清空废纸篓的方法</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/09/empty-trash/" class="article-date">
  <time datetime="2015-09-09T11:11:37.000Z" itemprop="datePublished">2015-09-09</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>Mac系统一般情况下,清空废纸篓速度很慢.网上找到了一个快速清空的方法.<br>打开item2,<br>运行</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd ~&#x2F;.Trash</span><br><span class="line">rm -rf *</span><br></pre></td></tr></table></figure>
<p>如果不行,可以用更狠的命令..(一不小心就可能把系统全删了..)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rm -rf</span><br></pre></td></tr></table></figure>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%BB%91%E8%8B%B9%E6%9E%9C/" rel="tag">黑苹果</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-yahoo-reset-css"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/07/yahoo-reset-css/"
    >网上流传的yahoo工程师的初始化css设置</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/07/yahoo-reset-css/" class="article-date">
  <time datetime="2015-09-07T12:57:32.000Z" itemprop="datePublished">2015-09-07</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*css reset code *&#x2F;</span><br><span class="line"></span><br><span class="line">&#x2F;****  文字大小初始化,使1em&#x3D;10px *****&#x2F;</span><br><span class="line">body &#123;</span><br><span class="line">font-size:62.5%;</span><br><span class="line">&#125; &#x2F;* for IE&#x2F;Win *&#x2F;</span><br><span class="line">html&gt;body &#123;</span><br><span class="line">font-size:19px;</span><br><span class="line">&#125; &#x2F;* for everything else *&#x2F;</span><br><span class="line"></span><br><span class="line">&#x2F;*字体边框等初始化*&#x2F;</span><br><span class="line">body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td &#123;</span><br><span class="line"> padding: 0;</span><br><span class="line"> margin: 0;</span><br><span class="line"> &#125;</span><br><span class="line">table &#123;</span><br><span class="line"> border-collapse: collapse;</span><br><span class="line"> border-spacing: 0;</span><br><span class="line"> &#125;</span><br><span class="line">fieldset,img &#123;</span><br><span class="line"> border: 0;</span><br><span class="line"> &#125;</span><br><span class="line"> img &#123;</span><br><span class="line"> display:block;</span><br><span class="line"> float:left;</span><br><span class="line"> &#125;</span><br><span class="line">address,caption,cite,code,dfn,th,var &#123;</span><br><span class="line"> font-weight: normal;</span><br><span class="line"> font-style: normal;</span><br><span class="line"> &#125;</span><br><span class="line">ol,ul &#123;</span><br><span class="line"> list-style: none;</span><br><span class="line"> &#125;</span><br><span class="line">caption,th &#123;</span><br><span class="line"> text-align: left;</span><br><span class="line"> &#125;</span><br><span class="line">h1,h2,h3,h4,h5,h6 &#123;</span><br><span class="line"> font-weight: normal;</span><br><span class="line"> font-size: 100%;</span><br><span class="line"> &#125;</span><br><span class="line">q:before,q:after &#123;</span><br><span class="line"> content:&#39;&#39;;</span><br><span class="line"> &#125;</span><br><span class="line">abbr,acronym &#123; border: 0;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line">a &#123;</span><br><span class="line">text-decoration:none;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/html/" rel="tag">html</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-jacman-backup"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/06/jacman-backup/"
    >hexo主题Jacman配置文件的备份</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/06/jacman-backup/" class="article-date">
  <time datetime="2015-09-06T09:52:19.000Z" itemprop="datePublished">2015-09-06</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>主配置文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"># Hexo Configuration</span><br><span class="line">## Docs: http:&#x2F;&#x2F;hexo.io&#x2F;docs&#x2F;configuration.html</span><br><span class="line">## Source: https:&#x2F;&#x2F;github.com&#x2F;hexojs&#x2F;hexo&#x2F;</span><br><span class="line"></span><br><span class="line"># Site</span><br><span class="line">title: 小信&#39; Blog</span><br><span class="line">subtitle:</span><br><span class="line">description:</span><br><span class="line">author: ClutchBear</span><br><span class="line">language: zh-CN</span><br><span class="line">timezone:</span><br><span class="line"></span><br><span class="line"># URL</span><br><span class="line">## If your site is put in a subdirectory, set url as &#39;http:&#x2F;&#x2F;yoursite.com&#x2F;child&#39; and root as &#39;&#x2F;child&#x2F;&#39;</span><br><span class="line">url: http:&#x2F;&#x2F;playbear.github.io</span><br><span class="line">root: &#x2F;</span><br><span class="line">permalink: :year&#x2F;:month&#x2F;:day&#x2F;:title&#x2F;</span><br><span class="line">permalink_defaults:</span><br><span class="line"></span><br><span class="line"># Directory</span><br><span class="line">source_dir: source</span><br><span class="line">public_dir: public</span><br><span class="line">tag_dir: tags</span><br><span class="line">archive_dir: archives</span><br><span class="line">category_dir: categories</span><br><span class="line">code_dir: downloads&#x2F;code</span><br><span class="line">i18n_dir: :lang</span><br><span class="line">skip_render:</span><br><span class="line"></span><br><span class="line"># Writing</span><br><span class="line">new_post_name: :title.md # File name of new posts</span><br><span class="line">default_layout: post</span><br><span class="line">titlecase: false # Transform title into titlecase</span><br><span class="line">external_link: true # Open external links in new tab</span><br><span class="line">filename_case: 0</span><br><span class="line">render_drafts: false</span><br><span class="line">post_asset_folder: false</span><br><span class="line">relative_link: false</span><br><span class="line">future: true</span><br><span class="line">highlight:</span><br><span class="line">  enable: true</span><br><span class="line">  line_number: true</span><br><span class="line">  auto_detect: true</span><br><span class="line">  tab_replace:</span><br><span class="line"></span><br><span class="line"># Category &amp; Tag</span><br><span class="line">default_category: uncategorized</span><br><span class="line">category_map:</span><br><span class="line">tag_map:</span><br><span class="line"></span><br><span class="line"># Date &#x2F; Time format</span><br><span class="line">## Hexo uses Moment.js to parse and display date</span><br><span class="line">## You can customize the date format as defined in</span><br><span class="line">## http:&#x2F;&#x2F;momentjs.com&#x2F;docs&#x2F;#&#x2F;displaying&#x2F;format&#x2F;</span><br><span class="line">date_format: YYYY-MM-DD</span><br><span class="line">time_format: HH:mm:ss</span><br><span class="line"></span><br><span class="line"># Pagination</span><br><span class="line">## Set per_page to 0 to disable pagination</span><br><span class="line">per_page: 10</span><br><span class="line">pagination_dir: page</span><br><span class="line"></span><br><span class="line"># Extensions</span><br><span class="line">## Plugins: http:&#x2F;&#x2F;hexo.io&#x2F;plugins&#x2F;</span><br><span class="line">## Themes: http:&#x2F;&#x2F;hexo.io&#x2F;themes&#x2F;</span><br><span class="line">theme: jacman</span><br><span class="line">stylus:</span><br><span class="line">  compress: true</span><br><span class="line"># Deployment</span><br><span class="line">## Docs: http:&#x2F;&#x2F;hexo.io&#x2F;docs&#x2F;deployment.html</span><br><span class="line">deploy:</span><br><span class="line">  type: git</span><br><span class="line">  repository: https:&#x2F;&#x2F;github.com&#x2F;playbear&#x2F;playbear.github.io.git</span><br><span class="line">  branch: master</span><br><span class="line"></span><br><span class="line">index_generator:</span><br><span class="line">  per_page: 5 ##首页默认10篇文章标题 如果值为0不分页</span><br><span class="line"></span><br><span class="line">archive_generator:</span><br><span class="line">    per_page: 10 ##归档页面默认10篇文章标题</span><br><span class="line">    yearly: true  ##生成年视图</span><br><span class="line">    monthly: true ##生成月视图</span><br><span class="line"></span><br><span class="line">tag_generator:</span><br><span class="line">    per_page: 10 ##标签分类页面默认10篇文章</span><br><span class="line"></span><br><span class="line">category_generator:</span><br><span class="line">    per_page: 10 ###分类页面默认10篇文章</span><br><span class="line"></span><br><span class="line">feed:</span><br><span class="line">    type: atom ##feed类型 atom或者rss2</span><br><span class="line">    path: atom.xml ##feed路径</span><br><span class="line">    limit: 20  ##feed文章最小数量</span><br></pre></td></tr></table></figure>

<p>主题配置文件:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br></pre></td><td class="code"><pre><span class="line">##### Menu</span><br><span class="line">menu:</span><br><span class="line">  Home: &#x2F;</span><br><span class="line">  Archives: &#x2F;archives</span><br><span class="line">  About: &#x2F;about</span><br><span class="line">## you can create &#96;tags&#96; and &#96;categories&#96; folders in &#96;..&#x2F;source&#96;.</span><br><span class="line">## And create a &#96;index.md&#96; file in each of them.</span><br><span class="line">## set &#96;front-matter&#96;as</span><br><span class="line">## layout: tags (or categories)</span><br><span class="line">## title: tags (or categories)</span><br><span class="line">## ---</span><br><span class="line"></span><br><span class="line">#### Widgets</span><br><span class="line">widgets:</span><br><span class="line">- category</span><br><span class="line">- tag</span><br><span class="line">- links</span><br><span class="line">- douban</span><br><span class="line">- rss</span><br><span class="line">## provide seven widgets:category,tag,rss,archive,tagcloud,links,weibo,douban</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#### RSS</span><br><span class="line">rss: &#x2F;atom.xml ## RSS address.</span><br><span class="line"></span><br><span class="line">#### Image</span><br><span class="line">imglogo:</span><br><span class="line">  enable: false             ## display image logo true&#x2F;false.</span><br><span class="line">  src: #img&#x2F;logo.png        ## &#96;.svg&#96; and &#96;.png&#96; are recommended,please put image into the theme folder &#96;&#x2F;jacman&#x2F;source&#x2F;img&#96;.</span><br><span class="line">favicon: img&#x2F;favicon.ico   ## size:32px*32px,&#96;.ico&#96; is recommended,please put image into the theme folder &#96;&#x2F;jacman&#x2F;source&#x2F;img&#96;.</span><br><span class="line">apple_icon: #img&#x2F;jacman.jpg ## size:114px*114px,please put image into the theme folder &#96;&#x2F;jacman&#x2F;source&#x2F;img&#96;.</span><br><span class="line">author_img: #img&#x2F;author.jpg ## size:220px*220px.display author avatar picture.if don&#39;t want to display,please don&#39;t set this.</span><br><span class="line">banner_img: #img&#x2F;banner.jpg ## size:1920px*200px+. Banner Picture</span><br><span class="line">### Theme Color</span><br><span class="line">theme_color:</span><br><span class="line">    theme: &#39;#21272D&#39;    ##the defaut theme color is blue</span><br><span class="line"></span><br><span class="line"># 代码高亮主题</span><br><span class="line"># available: default | night</span><br><span class="line">highlight_theme: night</span><br><span class="line"></span><br><span class="line">#### index post is expanding or not</span><br><span class="line">index:</span><br><span class="line">  expand: true           ## default is unexpanding,so you can only see the short description of each post.</span><br><span class="line">  excerpt_link: Read More</span><br><span class="line"></span><br><span class="line">close_aside: false  #close sidebar in post page if true</span><br><span class="line">mathjax: false      #enable mathjax if true</span><br><span class="line"></span><br><span class="line">### Creative Commons License Support, see http:&#x2F;&#x2F;creativecommons.org&#x2F;</span><br><span class="line">### you can choose: by , by-nc , by-nc-nd , by-nc-sa , by-nd , by-sa , zero</span><br><span class="line">creative_commons: none</span><br><span class="line"></span><br><span class="line">#### Author information</span><br><span class="line">author:</span><br><span class="line">  intro_line1:  #&quot;Hello ,I&#39;m Larry Page in Google.&quot;    ## your introduction on the bottom of the page</span><br><span class="line">  intro_line2:  #&quot;This is my blog,believe it or not.&quot;  ## the 2nd line</span><br><span class="line">  weibo:      ## e.g. wuchong1014 or 2176287895 for http:&#x2F;&#x2F;weibo.com&#x2F;2176287895</span><br><span class="line">  weibo_verifier:  ## e.g. b3593ceb Your weibo-show widget verifier ,if you use weibo-show it is needed.</span><br><span class="line">  tsina:      ## e.g. 2176287895  Your weibo ID,It will be used in share button.</span><br><span class="line">  douban:     ## e.g. wuchong1014 or your id for https:&#x2F;&#x2F;www.douban.com&#x2F;people&#x2F;wuchong1014</span><br><span class="line">  zhihu:      ## e.g. jark  for http:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;jark</span><br><span class="line">  email:      ## e.g. imjark@gmail.com</span><br><span class="line">  twitter:    ## e.g. jarkwu for https:&#x2F;&#x2F;twitter.com&#x2F;jarkwu</span><br><span class="line">  github:     ## e.g. wuchong for https:&#x2F;&#x2F;github.com&#x2F;wuchong</span><br><span class="line">  facebook:   ## e.g. imjark for https:&#x2F;&#x2F;facebook.com&#x2F;imjark</span><br><span class="line">  linkedin:   ## e.g. wuchong1014 for https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;wuchong1014</span><br><span class="line">  google_plus:    ## e.g. &quot;111190881341800841449&quot; for https:&#x2F;&#x2F;plus.google.com&#x2F;u&#x2F;0&#x2F;111190881341800841449, the &quot;&quot; is needed!</span><br><span class="line">  stackoverflow:  ## e.g. 3222790 for http:&#x2F;&#x2F;stackoverflow.com&#x2F;users&#x2F;3222790&#x2F;jark</span><br><span class="line">## if you set them, the corresponding  share button will show on the footer</span><br><span class="line"></span><br><span class="line">#### Toc</span><br><span class="line">toc:</span><br><span class="line">  article: true   ## show contents in article.</span><br><span class="line">  aside: true     ## show contents in aside.</span><br><span class="line">## you can set both of the value to true of neither of them.</span><br><span class="line">## if you don&#39;t want display contents in a specified post,you can modify &#96;front-matter&#96; and add &#96;toc: false&#96;.</span><br><span class="line"></span><br><span class="line">#### Links</span><br><span class="line">links:</span><br><span class="line">  我的github: https:&#x2F;&#x2F;github.com&#x2F;playbear</span><br><span class="line">  我的知乎: http:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;ClutchBear</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#### Comment</span><br><span class="line">duoshuo_shortname: clutchbear</span><br><span class="line">disqus_shortname:     ## e.g. wuchong   your disqus short name.</span><br><span class="line"></span><br><span class="line">#### Share button</span><br><span class="line">jiathis:</span><br><span class="line">  enable: false ## if you use jiathis as your share tool,the built-in share tool won&#39;t be display.</span><br><span class="line">  id:    ## e.g. 1889330 your jiathis ID.</span><br><span class="line">  tsina: ## e.g. 2176287895 Your weibo id,It will be used in share button.</span><br><span class="line"></span><br><span class="line">#### Analytics</span><br><span class="line">google_analytics:</span><br><span class="line">  enable: false</span><br><span class="line">  id:        ## e.g. UA-46321946-2 your google analytics ID.</span><br><span class="line">  site:      ## e.g. wuchong.me your google analytics site or set the value as auto.</span><br><span class="line">## You MUST upgrade to Universal Analytics first!</span><br><span class="line">## https:&#x2F;&#x2F;developers.google.com&#x2F;analytics&#x2F;devguides&#x2F;collection&#x2F;upgrade&#x2F;?hl&#x3D;zh_CN</span><br><span class="line">baidu_tongji:</span><br><span class="line">  enable: false</span><br><span class="line">  sitecode:  ## e.g. e6d1f421bbc9962127a50488f9ed37d1 your baidu tongji site code</span><br><span class="line">cnzz_tongji:</span><br><span class="line">  enable: false</span><br><span class="line">  siteid:    ## e.g. 1253575964 your cnzz tongji site id</span><br><span class="line"></span><br><span class="line">#### Miscellaneous</span><br><span class="line">ShowCustomFont: false  ## you can change custom font in &#96;variable.styl&#96; and &#96;font.styl&#96; which in the theme folder &#96;&#x2F;jacman&#x2F;source&#x2F;css&#96;.</span><br><span class="line">fancybox: true        ## if you use gallery post or want use fancybox please set the value to true.</span><br><span class="line">totop: true           ## if you want to scroll to top in every post set the value to true</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#### Custom Search</span><br><span class="line">google_cse:</span><br><span class="line">  enable: false</span><br><span class="line">  cx:   ## e.g. 018294693190868310296:abnhpuysycw your Custom Search ID.</span><br><span class="line">## https:&#x2F;&#x2F;www.google.com&#x2F;cse&#x2F;</span><br><span class="line">## To enable the custom search You must create a &quot;search&quot; folder in &#39;&#x2F;source&#39; and a &quot;index.md&quot; file</span><br><span class="line">## set the &#39;front-matter&#39; as</span><br><span class="line">## layout: search</span><br><span class="line">## title: search</span><br><span class="line">## ---</span><br><span class="line">baidu_search:     ## http:&#x2F;&#x2F;zn.baidu.com&#x2F;</span><br><span class="line">  enable: false</span><br><span class="line">  id:   ## e.g. &quot;783281470518440642&quot;  for your baidu search id</span><br><span class="line">  site: http:&#x2F;&#x2F;zhannei.baidu.com&#x2F;cse&#x2F;search  ## your can change to your site instead of the default site</span><br><span class="line"></span><br><span class="line">tinysou_search:     ## http:&#x2F;&#x2F;tinysou.com&#x2F;</span><br><span class="line">  enable: false</span><br><span class="line">  id:  ## e.g. &quot;4ac092ad8d749fdc6293&quot; for your tiny search id</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>其中Rss需要按装插件:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-feed@1 --save</span><br></pre></td></tr></table></figure>

<p>参考: </p>
<ul>
<li><p><a target="_blank" rel="noopener" href="http://wsgzao.github.io/post/hexo-jacman/">Jacman基于Pacman修改的Hexo主题</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://wuchong.me/blog/2014/11/20/how-to-use-jacman/">如何使用 Jacman 主题</a></p>
</li>
</ul>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/hexo/" rel="tag">hexo</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-time-strftime-fuction"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/02/time-strftime-fuction/"
    >time.strftime()用法</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/02/time-strftime-fuction/" class="article-date">
  <time datetime="2015-09-02T14:28:40.000Z" itemprop="datePublished">2015-09-02</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>参考 <a target="_blank" rel="noopener" href="http://www.w3cschool.cc/python/att-time-strftime.html">链接</a> 和 <a target="_blank" rel="noopener" href="https://github.com/qiwsir/ITArticles/blob/master/Python/%E8%8E%B7%E5%8F%96%E6%97%B6%E9%97%B4%E7%9A%84%E6%96%B9%E6%B3%95.md">链接</a></p>
<h3 id="描述"><a href="#描述" class="headerlink" title="描述"></a>描述</h3><p>Python time strftime() 函数接收以时间元组，并返回以可读字符串表示的当地时间，格式由参数format决定。</p>
<h3 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h3><p>strftime()方法语法：</p>
<pre><code>time.strftime(format[, t])
</code></pre>
<h3 id="说明"><a href="#说明" class="headerlink" title="说明"></a>说明</h3><p>python中时间日期格式化符号：</p>
<p>%y 两位数的年份表示（00-99）<br>%Y 四位数的年份表示（000-9999）<br>%m 月份（01-12）<br>%d 月内中的一天（0-31）<br>%H 24小时制小时数（0-23）<br>%I 12小时制小时数（01-12）<br>%M 分钟数（00=59）<br>%S 秒（00-59）<br>%a 本地简化星期名称<br>%A 本地完整星期名称<br>%b 本地简化的月份名称<br>%B 本地完整的月份名称<br>%c 本地相应的日期表示和时间表示<br>%j 年内的一天（001-366）<br>%p 本地A.M.或P.M.的等价符<br>%U 一年中的星期数（00-53）星期天为星期的开始<br>%w 星期（0-6），星期天为星期的开始<br>%W 一年中的星期数（00-53）星期一为星期的开始<br>%x 本地相应的日期表示<br>%X 本地相应的时间表示<br>%Z 当前时区的名称<br>%% %号本身</p>
<h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><ul>
<li>###获取时间的方法</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">&gt;&gt;&gt;import time</span><br><span class="line">&gt;&gt;&gt;this_time&#x3D;time.localtime()</span><br><span class="line">&gt;&gt;&gt; this_time</span><br><span class="line">time.struct_time(tm_year&#x3D;2013, tm_mon&#x3D;6, tm_mday&#x3D;6, tm_hour&#x3D;13, tm_min&#x3D;42, tm_sec&#x3D;38, tm_wday&#x3D;3, tm_yday&#x3D;157, tm_isdst&#x3D;0)</span><br><span class="line">&gt;&gt;&gt; type(this_time)</span><br><span class="line">&lt;type &#39;time.struct_time&#39;&gt;</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; this_year&#x3D;this_time[0]</span><br><span class="line">&gt;&gt;&gt; this_year</span><br><span class="line">2013</span><br><span class="line">&gt;&gt;&gt; for time in this_time:</span><br><span class="line">...     print time</span><br><span class="line">...</span><br><span class="line">2013</span><br><span class="line">6</span><br><span class="line">6</span><br><span class="line">13</span><br><span class="line">42</span><br><span class="line">38</span><br><span class="line">3</span><br><span class="line">157</span><br><span class="line">0</span><br><span class="line"></span><br><span class="line">time.strftime(&#39;%Y-%m-%d %T&#39;,time.localtime(time.time())</span><br><span class="line"> # 2014-09-04 23:42:34</span><br></pre></td></tr></table></figure>

<ul>
<li><h3 id="取过去具体时间的方法"><a href="#取过去具体时间的方法" class="headerlink" title="取过去具体时间的方法:"></a>取过去具体时间的方法:</h3></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">import time</span><br><span class="line"></span><br><span class="line"> #取一天前的当前具体时间</span><br><span class="line">time.strftime(&#39;%Y-%m-%d %T&#39;,time.localtime(time.time()-24*60*60))</span><br><span class="line"></span><br><span class="line"> #取20天前的当前具体时间</span><br><span class="line">time.strftime(&#39;%Y-%m-%d %T&#39;,time.localtime(time.time()-20*24*60*60))</span><br><span class="line"></span><br><span class="line"> #取20天前当前具体时间的前2小时</span><br><span class="line">time.strftime(&#39;%Y-%m-%d %T&#39;,time.localtime(time.time()-20*24*60*60-2*60*60))</span><br></pre></td></tr></table></figure>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-zhihu-login"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/02/zhihu-login/"
    >知乎上值得我学习的python回答 一</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/02/zhihu-login/" class="article-date">
  <time datetime="2015-09-02T14:23:39.000Z" itemprop="datePublished">2015-09-02</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <ul>
<li><h3 id="Lambda表达式有何用处？如何使用？"><a href="#Lambda表达式有何用处？如何使用？" class="headerlink" title="Lambda表达式有何用处？如何使用？"></a>Lambda表达式有何用处？如何使用？</h3><a target="_blank" rel="noopener" href="http://www.zhihu.com/question/20125256">原文链接点我</a>###涛吴:<br>简单来说，编程中提到的 lambda 表达式，通常是在需要一个函数，但是又不想费神去命名一个函数的场合下使用，也就是指匿名函数。这一用法跟所谓 λ 演算（题目说明里的维基链接）的关系，有点像原子弹和质能方程的关系，差别其实还是挺大的。</li>
</ul>
<p>不谈形式化的 λ 演算，只说有实际用途的匿名函数。先举一个普通的 Python 例子：将一个 list 里的每个元素都平方：</p>
<pre><code>map( lambda x: x*x, [y for y in range(10)] )
</code></pre>
<p>这个写法要好过</p>
<pre><code>def sq(x):
   return x * x

map(sq, [y for y in range(10)])
</code></pre>
<p>，因为后者多定义了一个（污染环境的）函数，尤其如果这个函数只会使用一次的话。而且第一种写法实际上更易读，因为那个映射到列表上的函数具体是要做什么，非常一目了然。如果你仔细观察自己的代码，会发现这种场景其实很常见：你在某处就真的只需要一个能做一件事情的函数而已，连它叫什么名字都无关紧要。Lambda 表达式就可以用来做这件事。</p>
<p>进一步讲，匿名函数本质上就是一个函数，它所抽象出来的东西是一组运算。这是什么意思呢？类比</p>
<pre><code>a = [1, 2, 3]
</code></pre>
<p>和</p>
<pre><code>f = lambda x : x + 1
</code></pre>
<p>，你会发现，等号右边的东西完全可以脱离等号左边的东西而存在，等号左边的名字只是右边之实体的标识符。如果你能习惯 [1, 2, 3] 单独存在，那么 lambda x : x + 1 也能单独存在其实也就不难理解了，它的意义就是给「某个数加一」这一运算本身。</p>
<p>现在回头来看 map() 函数，它可以将一个函数映射到一个可枚举类型上面。沿用上面给出的 a 和 f，可以写：<br>map(f, a)<br>也就是将函数 f 依次套用在 a 的每一个元素上面，获得结果 [2, 3, 4]。现在用 lambda 表达式来替换 f，就变成：</p>
<pre><code>map( lambda x : x + 1, [1, 2, 3] )
</code></pre>
<p> 会不会觉得现在很一目了然了？尤其是类比</p>
<pre><code>a = [1, 2, 3]
r = []
for each in a:
   r.append(each+1)
</code></pre>
<p>这样的写法时，你会发现自己如果能将「遍历列表，给遇到的每个元素都做某种运算」的过程从一个循环里抽象出来成为一个函数 map，然后用 lambda 表达式将这种运算作为参数传给 map 的话，考虑事情的思维层级会高出一些来，需要顾及的细节也少了一点。Python 之中，类似能用到 lambda 表达式的「高级」函数还有 reduce、filter 等等，很多语言也都有这样的工具（不过这些特性最好不要在 Python 中用太多，[原因详见] (<a target="_blank" rel="noopener" href="http://www.zhihu.com/question/19794855/answer/12987428">http://www.zhihu.com/question/19794855/answer/12987428</a>) 的评论部分）。这种能够接受一个函数作为参数的函数叫做「高阶函数」（higher-order function），是来自函数式编程（functional programming）的思想。</p>
<p>和其他很多语言相比，Python 的 lambda 限制多多，最严重的当属它只能由一条表达式组成。这个限制主要是为了防止滥用，因为当人们发觉 lambda 很方便，就比较容易滥用，可是用多了会让程序看起来不那么清晰，毕竟每个人对于抽象层级的忍耐 / 理解程度都有所不同。</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-sublime-backup"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/02/sublime-backup/"
    >sublime bakcup</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/02/sublime-backup/" class="article-date">
  <time datetime="2015-09-02T14:16:56.000Z" itemprop="datePublished">2015-09-02</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="setting-user"><a href="#setting-user" class="headerlink" title="setting-user"></a>setting-user</h2><pre><code>&#123;
&quot;caret_style&quot;: &quot;wide&quot;,
&quot;default_encoding&quot;: &quot;UTF-8&quot;,
&quot;draw_white_space&quot;: &quot;all&quot;,
&quot;font_face&quot;: &quot;Source Code Pro&quot;,
&quot;font_size&quot;: 16,
&quot;ignored_packages&quot;:
[
    &quot;Markdown&quot;,
    &quot;Vintage&quot;
],
&quot;line_padding_bottom&quot;: 1,
&quot;line_padding_top&quot;: 1,
&quot;match_brackets&quot;: true,
&quot;match_brackets_angle&quot;: true,
&quot;match_brackets_braces&quot;: true,
&quot;match_brackets_content&quot;: true,
&quot;match_brackets_square&quot;: true,
&quot;save_on_focus_lost&quot;: true,
&quot;soda_classic_tabs&quot;: true,
&quot;tab_size&quot;: 4,
&quot;theme&quot;: &quot;Soda Dark 3.sublime-theme&quot;,
&quot;translate_tabs_to_spaces&quot;: true,
&quot;trim_automatic_white_space&quot;: true,
&quot;trim_trailing_white_space_on_save&quot;: true
&#125;
</code></pre>
<h2 id="color-scheme-made-of-code"><a href="#color-scheme-made-of-code" class="headerlink" title="color_scheme:made of code"></a>color_scheme:made of code</h2><p> 下载地址: </p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https:&#x2F;&#x2F;github.com&#x2F;kumarnitin&#x2F;made-of-code-tmbundle&#x2F;</span><br></pre></td></tr></table></figure>
<pre><code>      如果下载失败可以新建一个文本文件,把代码拷贝保存到文本文件里面,然后改名成made of Code.tmTheme
       
</code></pre>
<p> 使用方法:  打开perferences–brow package,将Theme - Soda文件夹拷贝进入，然后就可以在Preferences -&gt; Color Scheme选择made of code。</p>
<h2 id="theme"><a href="#theme" class="headerlink" title="theme"></a>theme</h2><p>下载地址:<a target="_blank" rel="noopener" href="http://buymeasoda.github.io/soda-theme/">http://buymeasoda.github.io/soda-theme/</a></p>
<p>git clone <a target="_blank" rel="noopener" href="https://github.com/buymeasoda/soda-theme/">https://github.com/buymeasoda/soda-theme/</a> “Theme - Soda”</p>
<p>下载完成后,打开perferences–brow package,将Theme - Soda文件夹拷贝进入,<br>然后在setting-user设置文件中加入一行,<br>“theme”: “Soda Dark 3.sublime-theme”,<br>之后重启sublime text</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%BD%AF%E4%BB%B6/" rel="tag">软件</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
    <article
  id="post-python-jiecheng"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2015/09/02/python-jiecheng/"
    >给定数字N的阶乘N!的末尾有多少个0</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2015/09/02/python-jiecheng/" class="article-date">
  <time datetime="2015-09-02T14:13:38.000Z" itemprop="datePublished">2015-09-02</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <p>当n到二三十时候,N!已经非常大了,会溢出.<br>肯定不能用直接计算出阶乘的方式来统计0的个数.</p>
<p>通常用1到n的数字中,每个数字分解出2和5的个数,因为2 * 5 = 10<br>因为2个数非常多,因此只要算出5的个数就可以了</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">def zero_num(N):</span><br><span class="line">    count &#x3D; 0</span><br><span class="line">    for j in range(1, N + 1):</span><br><span class="line">        while j % 5 &#x3D;&#x3D; 0:</span><br><span class="line">           j &#x2F;&#x3D; 5</span><br><span class="line">           count +&#x3D; 1</span><br><span class="line">    return b</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li></ul>

    </footer>
  </div>

    
 
    
</article>

    
  </article>
  

  
  <nav class="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/3/">上一页</a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><span class="page-number current">4</span><a class="page-number" href="/page/5/">5</a><a class="page-number" href="/page/6/">6</a><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" href="/page/5/">下一页</a>
  </nav>
  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2022
        <i class="ri-heart-fill heart_icon"></i> 小信
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="40+岁大龄码农的自我修养"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>